module BetsHelper
  def bet_status(bet)
    if bet.played?
      str = case bet.win
            when nil
              image_tag("draw.png")
            when true
              if bet.winstreak_value == 0.5
                image_tag("half_win.png")
              else
                image_tag("win.png")
              end
            when false
              if bet.winstreak_value == 0.5
                image_tag("half_lose.png")
              else
                image_tag("lose.png")
              end
            end
      str << "<br/>" + format_time(bet.match.begin_at,:date)
    else
      format_time bet.match.begin_at,:datetime
    end
  end

  def bet_html_class(bet,team_id)
    if bet.team_id == team_id
      "class='bet-selected'"
    else
      ""
    end
  end

  def bet_html_style(bet,team_id)
    base_sty<le = "border-color:#D8DFEA;border-style:dotted dotted solid;border-width:1px;padding:4px;text-align:center;"
    bet_html_class(bet,team_id).blank? ? "style='#{base_style}'" : "style='#{base_style}background-color:#E7FBC8;'"
  end


  def user_next_bet(user)
  	nextBet = user.next_bet
    if nextBet.nil?
      	return "----"
    else           
      
      res = current_user.challenge_status(user,nextBet.match.id)
      resStatus =  res[:status] 
     # res[:status]
     displayString = ""
      if resStatus !="ch_expired" 
	      displayString =nextBet.match.home_team.displayed_name + "<br> vs. <br>" +  nextBet.match.away_team.displayed_name + "<br>" +format_time(nextBet.match.begin_at,:datetime)+ "<br>"
	      displayString +=render(:partial=>"friends_bet/" + resStatus,:locals=>{:u=>user,:sid=>user.next_bet.match.id,:ch=>res[:ch]}).gsub("<br/>"," ")
      else
 	     displayString =nextBet.match.home_team.displayed_name + "<br> vs. <br>" +  nextBet.match.away_team.displayed_name + "<br>"
      end 
      
      return displayString
	 
    end
  end

end










